#!/bin/bash

# MySQL数据库连接信息
DB_NAME="gameusd"

# 备份文件存放路径
BACKUP_DIR="$HOME/mysql/backup"

# 备份文件名
BACKUP_FILE="${BACKUP_DIR}/backup_$(date +%Y%m%d_%H%M%S).sql"

# 使用 mysqldump 命令备份数据库
mysqldump -h "127.0.0.1" "${DB_NAME}" >"${BACKUP_FILE}"

# 检查备份是否成功
# shellcheck disable=SC2181
if [ $? -eq 0 ]; then
  echo "MySQL backup successful. Backup file: ${BACKUP_FILE}"
else
  echo "MySQL backup failed."
fi
